package com.github.yealove.configgen.exception;

import com.github.yealove.configgen.dto.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalDefaultExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public R defaultErrorHandler(Exception e) {
        return R.fail(-1, e.getMessage());
    }

    @ExceptionHandler(value = ConfigGenException.class)
    public R configGenExceptionHandler(ConfigGenException e) {
        log.error(e.getMessage(), e);
        return R.fail(e.getCode(), e.getMessage());
    }
}